package com.notetool.datafetching;

import com.notetool.model.NoteSet;
import com.notetool.util.tokenparser.TokenList;

public class Query
{
    
    ////////////////////
    // Members
    private QueryNode root;
    
    ////////////////////
    // Constructors
    public Query (QueryNode rootNode)
    {
        root = rootNode;
    }
    
    ////////////////////
    // Accessors
    
    ////////////////////
    // Public static methods
    public static Query buildFrom (TokenList tokens, IQueryMonitor monitor) throws QueryInitException, QueryStoppedException
    {
        if (tokens == null)
            return null;
        
        return new Query (new ComposedQueryNode (tokens.getFirst (), tokens.getLast (), monitor));
    }
    
    ////////////////////
    // Public methods
    public NoteSet run (IQueryMonitor monitor) throws QueryExecException, QueryStoppedException
    {
        return root.getNotes (monitor);
    }

}
